<template>
	<div style="width: 100%; height: 100%; position: relative;">
		<div class="container">
			<el-table border :data="tableData" style="width: 100%" :default-sort="{prop: 'date', order: 'descending'}">
				<el-table-column prop="date" label="日期" sortable width="180">
				</el-table-column>
				<el-table-column prop="sort" label="序号" sortable width="180">
				</el-table-column>
				<el-table-column prop="tags" label="标签" sortable width="180">
					<template slot-scope="scope">
						<el-tag style="margin: 0 5px;" v-for="itam in scope.row.tags" type="primary"
							disable-transitions>{{itam}}</el-tag>
					</template>
				</el-table-column>
				<el-table-column prop="name" label="名称" width="240">
				</el-table-column>
				<el-table-column prop="picture_swiper" label="图片地址"width="200">
					<template slot-scope="scope">
						<div style="height: 200px;width: 300px;">
							<el-carousel :autoplay="false" height="200px" indicator-position="outside">
								<el-carousel-item v-for="item in scope.row.picture_swiper">
									<img :src="item" style="height: 200px;" alt="" srcset="" />
								</el-carousel-item>
							</el-carousel>
						</div>
				
					</template>
				</el-table-column>
				<el-table-column prop="price" label="售价" sortable width="180">
				</el-table-column>
				<el-table-column prop="state" label="状态" width="180">
					<template slot-scope="scope">
						<el-tag :type="scope.row.state == true ? 'success' : 'info'"
							disable-transitions>{{scope.row.state==true ? '上架' : "下架"}}</el-tag>
					</template>
				</el-table-column>
				<el-table-column label="操作">
					<template slot-scope="scope">
						<el-button size="mini" @click="pass(scope.row)">通过</el-button>
						<el-button size="mini" @click="pass(scope.row)" type="danger"
							>删除</el-button>
					</template>
				</el-table-column>
			</el-table>
		</div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				tableData: []
			};
		},
		created() {
			let _id = '6625e7c9fe975f74409546d6'
			let col = uniCloud.importObject('nyGoodsPictureObj', {
				customUI: true
			})
			let col1 = uniCloud.importObject('nyImagepackTgaObj', {
				customUI: true
			})
			let alltag = []
			col1.getImagepackTag().then((rea) => {
				console.log(rea.data.data)
				alltag = rea.data.data
				col.lookgoosPicture({'examine':'待审核'}).then((res) => {
					console.log(res.data)
					res.data.map((n, m) => {
						let date = n.create_date
						let tags = []
						n.picture_type.map(n => {
							alltag.map(j => {
								if (j._id == n) {
									tags.push(j.name)
								}
							})
						})
						console.log(n.state)
						this.tableData.push({
							"date": `${date[0]}${date[1]}${date[2]}${date[3]}-${date[4]}${date[5]}-${date[6]}${date[7]}`,
							"sort": n.sort,
							"tags": tags,
							"name": n.name,
							"price": n.price,
							"volume": n.volume,
							"state": n.state,
							"_id":n._id,
							"picture_swiper":n.picture_swiper
						})
					})
				})
			})


		},
		methods: {
			formatter(row, column) {
				return row.address;
			},
			pass(e){
				console.log(e)
				let col = uniCloud.importObject('nyGoodsPictureObj', {
					customUI: true
				})
				col.updategoodsPicture(e._id,{'examine':'审核通过'}).then((res)=>{
					console.log(res)
					this.$emit('fuc', 'goodexamine', '');
					this.$router.go(0);
				})
			},
			fail(e){
				let col = uniCloud.importObject('nyGoodsPictureObj', {
					customUI: true
				})
				col.updategoodsPicture(e._id,{'examine':'审核未通过'}).then((res)=>{
					console.log(res)
					this.$emit('fuc', 'goodexamine', '');
				})
			},
			get(){
				let _id = '6625e7c9fe975f74409546d6'
				let col = uniCloud.importObject('nyGoodsPictureObj', {
					customUI: true
				})
				let col1 = uniCloud.importObject('nyImagepackTgaObj', {
					customUI: true
				})
				let alltag = []
				col1.getImagepackTag().then((rea) => {
					console.log(rea.data.data)
					alltag = rea.data.data
					col.lookgoosPicture({'examine':'待审核'}).then((res) => {
						console.log(res.data)
						res.data.map((n, m) => {
							let date = n.create_date
							let tags = []
							n.picture_type.map(n => {
								alltag.map(j => {
									if (j._id == n) {
										tags.push(j.name)
									}
								})
							})
							console.log(n.state)
							this.tableData.push({
								"date": `${date[0]}${date[1]}${date[2]}${date[3]}-${date[4]}${date[5]}-${date[6]}${date[7]}`,
								"sort": n.sort,
								"tags": tags,
								"name": n.name,
								"price": n.price,
								"volume": n.volume,
								"state": n.state,
								"_id":n._id,
								"picture_swiper":n.picture_swiper
							})
						})
					})
				})
			}
		}
	}
</script>

<style lang="scss">
	.container {
		margin: 0;
		padding: 0;
		background-color: #fff;
		width: 100%;
		height: 97%;
		overflow-y: auto;
		overflow-x: hidden;

	}
</style>